const loaderUtils = require('loader-utils')
const fs = require('fs-extra')
const { resolve } = require('path')
const con = require('consolidate') //模版引擎

const render = (lang, html, opt) => new Promise(resolve => {
  con[lang]
    .render(html, opt, (err, res) => {
      if (err) throw err

      resolve(res)
    })
})

module.exports = async function (template) {
  this.cacheable()
  debugger
  const options = loaderUtils.getOptions(this)
  const file = options.type === 'wx' ? "[name].wxml" :"[name].axml" ;
  const fullPath = loaderUtils.interpolateName(this, `[path][name].vue`, options)
  const filename = loaderUtils.interpolateName(this, file, options)
  const folder = loaderUtils.interpolateName(this, `[folder]`, options)
  let html = template.content

  const dist = options.dist || 'dist'

    // html.

  fs.outputFileSync(resolve(process.cwd(), `${dist}/pages/${folder}/${filename}`), html, 'utf8')
  
  return ``
}